<?php   // $Id: admin_xml.php 347 2012-05-07 09:11:55Z pcoustillas $ ?>
<?php  
//Ce fichier construit la page de configuration a prtir de config.xml.
require_once("include/verif.php");

$conf_xml=simplexml_load_file('include/config.xml');
if (isset($_POST['submit'])) 
{
//ca viens d'etre posté, il faut donc effectuer la mise à jour
			
	foreach ($_POST as $champ => $valeur)
	{
		if ($champ != "submit") {
			$tab_noeud=preg_split("@/@",$champ);
		
			$conf_xml->$tab_noeud[0]->$tab_noeud[1]=$valeur;
			//$conf_xml->asXML('include/config.xml');
		}
	}
	//enregistrer le nouveau XML
	$conf_xml->asXML('include/config.xml');
	// on ré-affiche la page afin que si y'a un changement de theme ca se mette à jour
	//header("Location: admin_xml.php");
}

require_once("include/config/common.php");
require_once("include/language/$lang.php");
require_once("include/utils.php");
require_once("include/headers.php");


?>
<table class="page" align="center">
	<tr>
		<td class="page" align="center">
			<?php
			require_once("include/head.php");
			if ($user_admin != "y") {
				echo "<h1>$lang_admin_droit</h1>";
				exit;
			}
			?>
		</td>
	</tr>

	<tr>
		<td class="page" align="center">
		<center>
		<?php
		if (isset($_GET['message']))
		{
			echo "<h1>" . $_GET['message'] . "</h1>";
		}
		?>
		
		<form name="config_xml" method="post" action="admin_xml.php">

			<table class="boiteaction">
			<caption>
				<?php aff_lang("Configuration de votre OpenDCF"); ?> &nbsp; &nbsp; &nbsp; <?php bouton_aide("configuration") ?>
			</caption>
			<?php
			foreach ($conf_xml->children() as $theme => $data) 
			{
			?>
				<tr>
					<td class="texte1" colspan="2">
						<h2> <?php  echo "$theme " ?></h2>
					</td>
				</tr>
				<?php
				foreach ($conf_xml->$theme->children() as $nom => $valeur )
				{
				?>
				<tr>
					<td class="texte0"><?php echo $valeur['desc'] ?> &nbsp; &nbsp; &nbsp; <?php bouton_aide($nom) ?></td>
					<td class="texte0">
						<?php
						switch ($valeur['type']) {
						case "booleen":
						?>
							<select name="<?php echo $theme . "/" . $nom ?>">
								<option <?php if ($valeur=="oui") echo "selected='selected'" ?> value="oui" >oui</option>
								<option <?php if ($valeur=="non") echo "selected='selected'" ?> value="non" >non</option>
							</select>
						<?php
						break;
						case "liste":
						?>
							<select name="<?php   echo $theme . "/" . $nom ?>">
								<?php   $tab_liste=explode(";",$valeur['valeur']);
								foreach ($tab_liste as $element) {
									?>
									<option <?php if ($element==$valeur) echo "selected='selected'" ?> value="<?php   echo $element ?>" >
										<?php   echo $element ?>
									</option>
									<?php
								}
							?>
							</select>
						<?php  
						break;

						default:
						?>
							<input type="text" name="<?php echo $theme . "/" . $nom ?>" value="<?php echo $valeur ?>" />
						<?php
						}
						?>
					</td>
				</tr>
				<?php
				}	
				
			}
		?>
				<tr>
					<td colspan="3">
						<input type="hidden" name="submit" />
						<center>
							<input type="submit" />
						</center>
					</td>
				</tr>
			</table>
		
		</form>
		</center>
		</td>
	</tr>
	<tr>
		<td>
			<?php
			require_once("include/bas.php");
			?>
		</td>
	</tr>

</table>

</body>
</html>
